package org.zsl.aop.advice;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Component
public class ToolAspectAdvice {


    /**
     * 前置通知
     * */
    @Before("execution(* org.zsl.aop.dao.*.*(..))")
    public void before(){
        System.out.println("before:正在审核用户权限...");
    }

    /**
     * 后置通知
     * */
    @After("execution(* org.zsl.aop.dao.*.*(..))")
    public void after(){
        System.out.println("after:正在记录日志...");
    }


    /**
     *  环绕通知
     * */
    @Around("execution(* org.zsl.aop.dao.*.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("这是一个环绕通知的before...");

         Object object= point.proceed();
        System.out.println("这是一个环绕通知的after...");

         return object;
    }

    /**
     * 返回通知
     * */
    @AfterReturning("execution(* org.zsl.aop.dao.*.*(..))")
    public void afterReturning(JoinPoint joinPoint){

        System.out.println("切点方法名："+joinPoint.getSignature().getName());
        System.out.println("目标对象："+joinPoint.getTarget());
        System.out.println("打印日志···"+joinPoint.getSignature().getName()+"方法被执行了！");

    }

    // 异常通知
    @AfterThrowing(value = "execution(* org.zsl.aop.dao.*.*(..))",throwing = "e")
    public void myAfterThrowing(Exception e){
        System.out.println("异常通知···");
        System.out.println(e.getMessage());
    }


}
